package com.caregiver.watch.business.user.utils;

import com.caregiver.watch.business.user.context.SecurityContextHolder;
import com.caregiver.watch.common.exception.BaseException;
import com.caregiver.watch.common.exception.business.BusinessException;
import com.caregiver.watch.common.utils.number.LongUtils;

/**
 * @Description: 用户信息工具
 * @Author 疆戟
 * @Date 2025/8/17 10:41
 * @Version 1.0
 */
public final class UserInfoUtils {


    /**
     * 获取用户ID
     */
    public static Long getUserId() {
        Long userId = SecurityContextHolder.getUserId();
        if (LongUtils.isPositive(userId)) {
            return userId;
        }
        throw new BusinessException("不是有效的用户");
    }

    /**
     * 获取用户名称
     */
    public static String getUsername() {
        return SecurityContextHolder.getUserName();
    }

}
